<template>
    <div class="cateGray">
        <!-- 面包屑导航 -->
        <BreadView>
            <BreadItem :to="'/'">首页</BreadItem>
            <Transition name="bread">
                <BreadItem>{{ subCate && subCate.name }}</BreadItem>
            </Transition>
        </BreadView>
        <!-- 轮播图 -->
        <CateSwiper></CateSwiper>
        <!-- 所有二级分类 -->
        <div class="sub-list">
            <h3>全部分类</h3>
            <ul v-if="subCate">
                <li v-for="i in subCate.children" :key="i.id">
                    <a href="javascript:;">
                        <img :src="i.picture">
                        <p>{{ i.name }}</p>
                    </a>
                </li>
            </ul>
        </div>
        <!-- 子分类推荐数据 -->
        <!-- 分类一组件 -->
        <CateOne :nowId="nowId"></CateOne>
        <!-- 分类二组件 -->
        <CateTwo :nowId="nowId"></CateTwo>
        <!-- 分类三组件 -->
        <CateThree :nowId="nowId"></CateThree>
        <!-- 分类四组件 -->
        <CateFour :nowId="nowId"></CateFour>
    </div>
</template>

<script>
import BreadView from '@/components/bread/BreadView.vue'
import BreadItem from '@/components/bread/BreadItem.vue'
import CateSwiper from '@/components/cate/CateSwiper.vue'
import CateOne from '@/components/cate/CateOne.vue'
import CateTwo from '@/components/cate/CateTwo.vue'
import CateThree from '@/components/cate/CateThree.vue'
import CateFour from '@/components/cate/CateFour.vue'
export default {
    components: { BreadView, BreadItem, CateSwiper, CateOne, CateTwo, CateThree, CateFour },
    data() {
        return {
            nowId: null,
            nowName: null,
        }
    },
    methods: {

    },
    mounted() {
        //获取地址栏数据
        this.nowId = this.$route.query.id;
    },
    computed: {
        subCate() {
            // console.log(this.$store.state.category.cate)
            let nowObj = this.$store.state.category.cate.find(item => {
                return item.id == this.nowId;
            })

            return nowObj && nowObj
        }
    },
    watch: {
        $route: {
            handler(val) {
                this.nowId = val.query.id;
            }
        }
    }
}
</script>

<style lang="scss">
@import '../../assets/css/variables.scss';

h3 {
    font-size: 28px;
    color: #666;
    font-weight: normal;
    text-align: center;
    line-height: 100px;
}

.sub-list {
    margin-top: 20px;
    background-color: #fff;

    ul {
        display: flex;
        padding: 0 32px;
        flex-wrap: wrap;

        li {
            width: 168px;
            height: 160px;

            a {
                text-align: center;
                display: block;
                font-size: 16px;

                img {
                    width: 100px;
                    height: 100px;
                }

                p {
                    line-height: 40px;
                }

                &:hover {
                    color: $xtxColor;
                }
            }
        }
    }
}
.bread-enter,.bread-leave-to {
    opacity: 0;
    transform: translateX(-20px);
}
.bread-enter-to,.bread-leave {
    opacity: 1;
    transform: translateX(0);
}
.bread-leave-active {
    transition: all 0 0.3s;
}
</style>